home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 834 < prev    next >
Encoding:
Text File  |  1996-08-06  |  947 b   |  62 lines

  1. Path: RRZ.Uni-Koeln.DE!usenet
  2. From: a2867001@smail.rrz.Uni-Koeln.DE (Lars Kaderali)
  3. Newsgroups: comp.lang.c++
  4. Subject: Error?
  5. Date: Sun, 07 Jan 1996 20:33:28 GMT
  6. Organization: Regional Computing Center, University of Cologne
  7. Message-ID: <4cpaov$241@news.rrz.uni-koeln.de>
  8. NNTP-Posting-Host: annexr2-8.slip.uni-koeln.de
  9. X-Newsreader: Forte Free Agent v0.55
  10.  
  11. Hey folks! Need some help - I tried the following program in c++ on an
  12. ibm pc:
  13.  
  14. =======================================
  15.  
  16. //test
  17. #include <iostream.h>
  18. float a,b;
  19. main()
  20. {
  21.   a=-1.0; b=0.1;
  22.   while (a<1.1)
  23.   {
  24.     cout<<a<<endl;
  25.     a+=b;
  26.   }
  27. }
  28.  
  29. =======================================
  30.  
  31. which returns:
  32.  
  33. -1
  34. -0.9
  35. -0.8
  36. -0.7
  37. -0.6
  38. -0.5
  39. -0.4
  40. -0.3
  41. -0.2
  42. -0.1
  43. (so far as expected, but then:)
  44. 7.450581e-08     < ==== ??????????????
  45. 0.1
  46. 0.2
  47. 0.3
  48. 0.4
  49. 0.5
  50. 0.6
  51. 0.7
  52. 0.8
  53. 0.9
  54. 1
  55.  
  56. How come this 7.450581e-08 happens instead of 0.0 ?????
  57. Please reply directly via e-mail if you know to help!!!
  58. Thanx a lot!
  59.  
  60. Lars
  61.  
  62.